#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2020/9/27 21:40
# @Author  : leon yan
# @Site    :
# @File    : OneHeight.py
# @Software: PyCharm

from PyQt5.QtCore import pyqtSlot, pyqtSignal
from PyQt5.QtWidgets import QWidget, QApplication, QMessageBox

import Globalist as gl
from resource.OneHeight_ui import Ui_Form


class QOneHeight(QWidget, Ui_Form):
    def __init__(self, parent=None, *args, **kwargs):
        super().__init__(parent, *args, **kwargs)
        self.setupUi(self)
        self.widget.setTableSheet("oneHeight", False)
        self.widget.frame.setVisible(False)
        self.setTable()

        '''启动更新方法'''
        self.threadObj = gl.get_value("obj_UpdateThread")
        self.threadObj.bPulse.connect(self.do_UpdateStatus)

    def __del__(self):
        print("OneHeight is deleted")

    def closeEvent(self, event):
        pass

    def setTable(self):
        deviceIpDict = gl.global_var["deviceIpDict"]
        # print(deviceIpDict)
        curHeightDict = gl.global_var["Plc_read_area"]["data_rdArea4"]["dArea"]
        # print(curHeightDict)
        aa = []
        for key, value in curHeightDict.items():
            bb = []
            for i in range(len(value[2])):
                bb.append(value[2][i])
            bb2 = len(bb)
            for j in range(4 - bb2):
                bb.append("")
            bb.insert(0, deviceIpDict[int(key)][2])
            aa.append(bb)
        self.widget.fileToTable(aa)

    @pyqtSlot()
    def on_btnClose_clicked(self):
        self.close()

    @pyqtSlot()
    def on_btnApply_clicked(self):
        pass

    @pyqtSlot()
    def do_UpdateStatus(self):
        self.setTable()


if __name__ == '__main__':
    import sys

    app = QApplication(sys.argv)
    objWindow = QOneHeight()

    objWindow.show()
    sys.exit(app.exec_())
